<template>
	<view>
		<input v-model="inp" />
		<button @click="handleStart">开启BLE</button>
		<button @click="send">发送指令</button>
		<button @click="stop">停止指令</button>
		<button @click="isOpenGPS">定位开启判断</button>
		<button @click="createTab">创建</button>
		<button @click="addtab">添加</button>
		<button @click="getTab">获取</button>
		<button @click="setDebug">debug</button>
		<button @click="saveLog">保存日志</button>


	</view>
</template>

<script>
	import {
		hexToString
	} from '@/utils/index.js'
	import { cratePriceTable,addPrice,getPriceTypeToId } from '@/utils/sql/sqlPrice - 副本.js'
	export default {
		data() {
			return {
				inp: '',
				ble: uni.requireNativePlugin('ble'),

				time: null,
			}
		},
		methods: {
			setData() {
				let msg = '09ff66f1f2f3f4f5f65000000000000000000000000000000000000'
				let len = Number(msg.substr(0, 2));

				let newMsg = msg.substr(2, len * 2);
				let zl = newMsg.substr(2, 2);
				let msc = newMsg.substr(4, 12);
				let num = newMsg.substr(16, 2);
			},
			handleStart() {
				let that = this
				//初始化
				this.ble.init()
				//开始蓝牙广播监听
				this.ble.start()
				// //停止蓝牙广播监听
				// this.ble.stop()
				// //发送蓝牙广播
				// this.ble.sendCmd('99060504030201', 3, '')
				// //停止发送蓝牙广播
				// this.ble.stopSendCmd()
				// //设置过滤mac地址
				// this.ble.setMac('11:22:33:44:55:66')
				// //重置过滤mac地址
				// this.ble.resetMac()
				// //重置广播数据
				// this.ble.clearData()
				// /加密数据
				// this.ble.keeloqOutdata(productId, counter, day, productSecret, "0", sha,function(res) {
				// 	})

				// 接收数据
				this.time = setInterval(() => {
					that.ble.getBackData(function(res) {
						console.log('接收', res.data);
					})
				}, 2000)

			},
			// 写密码 c8060504030201295723245758
			// 
			send() {
				this.ble.sendCmd('99060504030201', 3, '') //不输入mac地址默认不过滤
				setTimeout(()=>{
					this.ble.stopSendCmd()
				},2000);
			},
			stop() {
				this.ble.stop()
			},
			isOpenGPS(){
				//判断定位服务是否开启
				console.log(this.ble.isOpenGPS()+'::::');
				this.ble.isUiThreadOpenGPS(function(res) {
						console.log('接收', res.code);//-1为未开 1为已开
					});
			},
			addtab(){
				addPrice({
					productModel:'123466',
					priceGroup:'i22ieji',
				}).then(res =>{
					console.log(res);
				})
			},
			getTab(){
				getPriceTypeToId('123466').then(res =>{
					console.log(res);
				})
			},
			setDebug(){
				//true开启debug模式
				this.ble.isDebug(true)
			},
			saveLog(){
				//保存日志
				this.ble.saveLog()
			},
			createTab(){
				cratePriceTable();
			},

		},
		mounted() {
			// this.ble.init()
			console.log('xxxxxxx');
		},
		onShow() {


		},
		onUnload() {
			clearInterval(this.time)
			this.ble.stop()
		}
	}
</script>

<style>

</style>